{extend name='common/_container'}
{block name="content"}
<div class="ibox float-e-margins">
<input type="hidden" name='id' id='id' value="{$info.id}" />
	<div class="ibox-content">
		<div class="form-horizontal" id="CodeInfoForm">
			<div class="row">
				<div class="col-sm-12">
				<!-- form start -->
					<div class="form-group">
						<label class="col-sm-2 control-label">项目名称：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="entry_name" value="{$info.entry_name}" name="entry_name" class="form-control" placeholder="请输入付费项目名称"  >
						</div>
					</div>

					<div class="form-group">
						<label class="col-sm-2 control-label">简介：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="comment"  value="{$info.comment}"   name="comment" class="form-control" placeholder="请输入简介"  >
						</div>
					</div>

					<div class="form-group layui-form">
						<label class="col-sm-2 control-label">收费模式：</label>
						<div class="col-sm-9">
							<select id="is_fixed_price" name="is_fixed_price">
								<option value="0" {if condition="$info.is_fixed_price eq '0'"}selected{/if}>固定金额</option>
								<option value="1" {if condition="$info.is_fixed_price eq '1'"}selected{/if}>红娘自定义</option>
							</select>
						</div>
					</div>
 

				<!-- form end -->
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9 col-sm-offset-1">
					<button type="button" class="btn btn-primary" onclick="CodeInfoDlg.update()" id="ensure">
						<i class="fa fa-check"></i>&nbsp;确认提交
					</button>
					<button type="button" class="btn btn-danger" onclick="CodeInfoDlg.close()" id="cancel">
						<i class="fa fa-eraser"></i>&nbsp;取消
					</button>
				</div>
			</div>
		</div>
	</div>
</div>

<!--	新增行的模板 		-->
<script id="tpl_matchmaker_money" type="text/html">
	<div class="form-group layui-form" id="group_matchmaker_money">
		<label class="col-sm-2 control-label">红娘等级：</label>
		<div class="col-sm-3">
			<select name="level_id" id="level_id" class="province-selector">
				<option value="">选择红娘等级</option>
				{foreach $level_rows as $key=>$vo }
				<option value="{$vo['id']}">{$vo['name']}</option>
				{/foreach}
			</select>
		</div>
		<label class="col-sm-1 control-label">收费金额：</label>
		<div class="col-sm-2">
			<input type="text" autocomplete="off" id="toll_money" name="toll_money" class="form-control" />
		</div>
		<label class="col-sm-2 control-label">分成金额：</label>
		<div class="col-sm-3">
			<input type="text" autocomplete="off" id="commission_rate" name="commission_rate" class="form-control" />
		</div>
		<div class="col-sm-1">
			<i id="addRow" class="layui-icon layui-icon-addition"></i>
			<i id="reduceRow" class="layui-icon layui-icon-subtraction"></i>
		</div>
	</div>
</script>

<!--	编辑初始化数据	-->
<script id="tpl_init_matchmaker_money" type="text/html">
	<div class="form-group layui-form" id="group_matchmaker_money">
		<label class="col-sm-2 control-label">红娘等级：</label>
		<div class="col-sm-3">
			<select name="level_id" id="level_id" class="province-selector">
				<option value="">选择红娘等级</option>
				{foreach $level_rows as $key=>$vo }
				<option value="{$vo['id']}" {{#  if(d.level_id =='{$vo['id']}'){ }}selected{{#  } }}>{$vo['name']}</option>
				{/foreach}
			</select>
		</div>
		<label class="col-sm-1 control-label">收费金额：</label>
		<div class="col-sm-2">
			<input type="text" autocomplete="off" id="toll_money" name="toll_money" value="{{= d.toll_money }}" class="form-control" />
		</div>

		<label class="col-sm-2 control-label">分成金额：</label>
		<div class="col-sm-3">
			<input type="text" autocomplete="off" id="commission_rate" name="toll_money" value="{{= d.commission_rate }}" class="form-control" />
		</div>
		<div class="col-sm-1">
			<i id="addRow" class="layui-icon layui-icon-addition"></i>
			<i id="reduceRow" class="layui-icon layui-icon-subtraction"></i>
		</div>
	</div>
</script>

<script src="__PUBLIC__/static/js/upload.js" charset="utf-8"></script>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<script>
	layui.use(['form','laytpl'],function(){
		laytpl = layui.laytpl;
		var form = layui.form;

		$(document).on('click', '#addRow', function() {
			addRow($(this));
			form.render(); // 渲染全部表单
		});

		$(document).on('click', '#reduceRow', function() {
			reduceRow($(this));
		});

		var matchmaker_money_json = <?php echo $info['matchmaker_money_json']; ?>;
		var getTpl = document.getElementById('tpl_init_matchmaker_money').innerHTML; // 获取模板字符
		for(var i = 0; i < matchmaker_money_json.length; i++) {
			laytpl(getTpl).render(matchmaker_money_json[i], function(str){
				$(".form-horizontal .row .col-sm-12").append(str);
			});
		}


		form.render(); // 渲染全部表单
	});

	var CodeInfoDlg = {
		CodeInfoData: {},
		validateFields: {
			entry_name: {
				validators: {
					notEmpty: {
						message: '项目名称不能为空'
					},
				}
			},
		 }
	}

	CodeInfoDlg.collectData = function () {
		this.set('id').set('entry_name').set('comment');
	};

	CodeInfoDlg.update = function () {
		this.clearData();
		this.collectData();
		if (!this.validate()) {
			return;
		}
		//遍历提取数据
		var matchmaker_money_json = [];
		$("div[id='group_matchmaker_money']").each(function() {
			var level_id = $(this).find("select[name='level_id'] option:selected").val();
			var toll_money = $(this).find("#toll_money").val();
			 var commission_rate = $(this).find("#commission_rate").val();
			matchmaker_money_json.push({
				level_id:level_id,
				toll_money:toll_money,
				commission_rate:commission_rate
			})
		});

		var ajax = new $ax(Feng.ctxPath + "/ZhMatchmakerCharge/update", function (data) {
			if ('00' === data.status) {
				Feng.success(data.msg,1000);
				window.parent.CodeGoods.table.refresh();
				CodeInfoDlg.close();
			} else {
				Feng.error(data.msg + "！",1000);
			}
		})
		ajax.set('matchmaker_money_json', JSON.stringify(matchmaker_money_json));
		ajax.set(this.CodeInfoData);
		ajax.start();
	};

	//增加一行
	function addRow(ele){
		var top_form_group = $(ele).parent().parent();
		var getTpl = document.getElementById('tpl_matchmaker_money').innerHTML; // 获取模板字符
		// 渲染并输出结果
		laytpl(getTpl).render({}, function(str){
			$(top_form_group).after(str);
		});
	}
	//删除一行
	function reduceRow(ele){
		var top_form_group = $(ele).parent().parent();
		$(top_form_group).remove();
	};

</script>
<script src="__PUBLIC__/static/js/base.js" charset="utf-8"></script>
{/block}
